package com.waigoulin.config;

import com.waigoulin.service.weixin.IWeixinApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import com.waigoulin.service.lbs.IpLocationApiService;

/**
 * @FileName Retrofit2Config
 * @Description TODO(一句话描述该类的功能)
 * @Author waigoulin
 * @date 2025-05-14
 **/

@Slf4j
@Configuration
public class Retrofit2Config {

    // 1. 微信开发平台配置
    private static final String WEIXIN_BASE_URL = "https://api.weixin.qq.com/";

    @Bean(name = "weixinRetrofit") // 命名Bean，区分不同实例
    public Retrofit weixinRetrofit() {
        return new Retrofit.Builder()
                .baseUrl(WEIXIN_BASE_URL)
                .addConverterFactory(JacksonConverterFactory.create()) // 复用Jackson解析
                .build();
    }

    @Bean
    public IWeixinApiService weixinApiService(@Qualifier("weixinRetrofit") Retrofit retrofit) {
        // 绑定微信的Retrofit实例
        return retrofit.create(IWeixinApiService.class);
    }


    // 2. 太平洋网络IP解析接口配置
    private static final String IP_BASE_URL = "https://whois.pconline.com.cn/";

    @Bean(name = "ipRetrofit") // 命名Bean，区分不同实例
    public Retrofit ipRetrofit() {
        return new Retrofit.Builder()
                .baseUrl(IP_BASE_URL)
                .addConverterFactory(JacksonConverterFactory.create()) // 复用Jackson解析（与微信一致）
                .build();
    }

    @Bean
    public IpLocationApiService ipLocationService(@Qualifier("ipRetrofit") Retrofit retrofit) {
        // 绑定IP解析的Retrofit实例
        return retrofit.create(IpLocationApiService.class);
    }

}


